<?php
/**
 * RedCross Application
 *
 * @copyright Copyright (c) 2010, Kristian Stokke Tryggestad, Rune Vikestad, Andreas Flaten Wist, Simen Nicolai Echholt, Ole Henrik Jahren
 */


/**
 * Class for easy handling of dates, to and from MySQL
 *
 * @category RedCross
 * @package RedCross
 */

class RedCross_Date extends Zend_Date
{
	const DB_FMT = 'y-MM-dd HH:mm:ss';
	/* Because the nb_NO locale in Zend is broken */
	const NO_DATE_FMT = 'dd.MM.y';
	const NO_TIME_FMT = 'HH:mm';
	const NO_DATETIME_FMT = 'dd.MM.y HH:mm';
	const NO_DATE_WITH_MONTH_AS_TEXT = 'd. MMMM - yyyy';

	/**
	 * Construct a date.
	 *
	 * @param string $date Date string in 'YYYY-MM-dd HH:mm:ss' format
	 */
	public function __construct($date = null, $part = null)
	{
		parent::__construct($date, $part, new Zend_Locale('nb_NO'));
	}

	/**
	 * Get date as string.
	 *
	 * @return string The date part of the object, as a string
	 */
	public function getDateStr()
	{
		return $this->get(self::NO_DATE_FMT);
	}

	/**
	 * Get time as string.
	 *
	 * @return string The time part of the object, as a string
	 */
	public function getTimeStr()
	{
		return $this->get(self::NO_TIME_FMT);
	}

	/**
	 * Get date and time as a string
	 *
	 * @return string The date and time part of the object, as a string
	 */
	public function getDateTimeStr()
	{
		return $this->getDateStr() . ' ' . $this->getTimeStr();
	}

	/**
	 * Get name of the day of the week.
	 *
	 * @return string The name of the day of the week, as a string.
	 */
	public function getDayStr()
	{
		return $this->get(self::WEEKDAY);
	}

	/**
	 * Get the number of the week.
	 *
	 * @return string The name of the day of the week, as a string.
	 */
	public function getWeekStr()
	{
		return $this->get(self::WEEK);
	}

	/**
	 * export date and time in db format
	 *
	 * @return string The date and time in database format, as a string
	 */
	public function export()
	{
		return $this->get(self::DB_FMT);
	}

	public function import($date)
	{
		return $this->set($date, self::DB_FMT);
	}
	
	public function exportWithMonthAsText()
	{
		return $this->get(self::NO_DATE_WITH_MONTH_AS_TEXT);
	}
}
